package barecodes;

/**
 *
 * @author Sawior
 */
import net.sourceforge.barbecue.Barcode;
import net.sourceforge.barbecue.BarcodeFactory;
import net.sourceforge.barbecue.BarcodeImageHandler;

import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.embed.swing.SwingFXUtils;
import javafx.scene.image.Image;
import net.sourceforge.barbecue.BarcodeException;
import net.sourceforge.barbecue.output.OutputException;

public class Ean18Generator {

    public static Image saveEanFile(Integer id) {
        String codedId = PassesIdCoder.codeId(id);
        Barcode barcode = null;
        try {
            barcode = BarcodeFactory.createEAN13(codedId);
            barcode.setBarHeight(60);
            barcode.setBarWidth(2);
        } catch (BarcodeException ex) {
            Logger.getLogger(Ean18Generator.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            return SwingFXUtils.toFXImage(BarcodeImageHandler.getImage(barcode), null);
        } catch (OutputException ex) {
            Logger.getLogger(Ean18Generator.class.getName()).log(Level.SEVERE, "[CarPark] cannot convert barcode image to javafx image", ex);
        }
        return null;

    }
}
